<template>
  <div class="ph-container">
    <!-- 标题 -->
    <h3>{{imgsinfo.title}}</h3>
    <!-- 摘要 -->
    <div class="ph-zy">
      <p>
        <span>发表时间：{{imgsinfo.add_time | dateFormat}}</span>
        <span>点击：{{imgsinfo.click}}次</span>
      </p>
    </div>
    <hr>
    <!-- 图片展示区域 -->
    <div>
      <!-- 缩略图区域 -->
      <div>
        <vue-preview
          :list="list"
          :thumbImageStyle="{width: '100px', height: '80px', margin: '10px'}"
          :tapToClose="true"
        />
      </div>
      <div>
        <img src alt>
      </div>
      <!-- 图片内容文字 -->
      <div class="content" v-html="imgsinfo.content"></div>
    </div>
    <!-- 评论子组件 -->
    <cmt-box :id="this.id"></cmt-box>
  </div>
</template>

<script>
import comment from "../subcomponents/comment.vue";
export default {
  data() {
    return {
      imgsinfo: {},
      id: this.$route.params.id, //通过路由获取图片id
      list: []
    };
  },
  created() {
    this.getImagesinfo();
    this.getImages();
  },
  methods: {
    getImagesinfo() {
      this.$http.get("api/getimageInfo/" + this.id).then(result => {
        if (result.body.status === 0) {
          this.imgsinfo = result.body.message[0];
        }
      });
    },
    getImages() {
      this.$http.get("api/getthumimages/" + this.id).then(result => {
        if (result.body.status === 0) {
          // 循环每个图片的数据，补全图片的宽和高
          result.body.message.forEach(item => {
            item.w = 600;
            item.h = 400;
          });
          // 把完整的数据保存到list中
          this.list = result.body.message;
        }
      });
    }
  },
  components: {
    "cmt-box": comment
  }
};
</script>

<style lang="scss" scoped>
.ph-container {
  margin-left: 5px;
  margin-right: 5px;
  
  h3 {
    color: blue;
    text-align: center;
    font-size: 16px;
    margin-top:15px;
    margin-bottom:10px;
  }
  .ph-zy {
    font-size: 13px;
    p {
      display: flex;
      justify-content: space-between;
    }
  }
  .content {
    font-size: 15px;
    line-height: 30px;
  }
}
</style>

